﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UsersForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            var name = textBox1.Text;
            var pwd = textBox2.Text;

            if (textBox1.Text != "" && textBox2.Text != "")
            {

                string sql = string.Format("select * from Users where Username='{0}' and Passwords='{1}'", name, pwd);

                DataTable mytable = DBHelper.Select(sql);

                var myrow = mytable.Rows.Count;

                if (myrow == 1)
                {
                    MessageBox.Show("登入成功", "提示");

                    this.Close();

                    Form3.StrartForm.toolStripStatusLabel1.Text += name;
                    

                    //显示主窗体
                    Form3.StrartForm.ShowInTaskbar = true;
                    Form3.StrartForm.WindowState = FormWindowState.Normal;
                }
                else
                {
                    MessageBox.Show("登入失败");
                }

            }
            else
            {
                MessageBox.Show("用户名和密码不能为空");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            Form3.StrartForm.Close();
        }
    }
}
